if (!dhtmlxValidation) dhtmlxValidation = {};	//用于非dhtmlx环境

//integer >=0
dhtmlxValidation.isValidPositiveInteger = function(value) {
	return !!value.toString().match(/(^-?\d+$)/) && Number(value)>=0;
};

//integer <=0
dhtmlxValidation.isValidNegativeInteger = function(value) {
	return !!value.toString().match(/(^-?\d+$)/) && Number(value)<=0;
};

//numeric >= 0
dhtmlxValidation.isValidPositiveNumeric = function(value) {
	return !!value.toString().match(/(^-?\d\d*[\.|,]\d*$)|(^-?\d\d*$)|(^-?[\.|,]\d\d*$)/) && Number(value)>=0;
};

//numeric <= 0
dhtmlxValidation.isValidNegativeNumeric = function(value) {
	return !!value.toString().match(/(^-?\d\d*[\.|,]\d*$)|(^-?\d\d*$)|(^-?[\.|,]\d\d*$)/) && Number(value)<=0;
};

//percent
dhtmlxValidation.isValidPercent = function(value) {
	return !!value.toString().match(/(^-?\d+$)/) && Number(value)>=0 && Number(value)<=100;
};

//valid class names splited by space
dhtmlxValidation.isValidClassNames=function(a){
	if (!a) return true;
	var b = a.split(' ');
	for (var i in b) {
		if (!b[i].toString().match(/^[_\-a-zA-Z][a-zA-Z0-9_-]*$/gi)) return false;
	}
    return true;
};

//valid variable name
dhtmlxValidation.isValidVariable=function(a){
	if (!a) return false;
	var b = a.split(' ');
	for (var i in b) {
		if (!b[i].toString().match(/^[_\-a-zA-Z][a-zA-Z0-9_]*$/gi)) return false;
	}
    return true;
};

//check requried content when {} is empty
dhtmlxValidation.isNotEmptyObject=function(a){
	if (!a) return false;
	if ('string'==typeof(a)) return false;
	for (var i in a) {
		return true;
	}
    return false;
};

//check requried content when {} is empty
dhtmlxValidation.isValidJsonstr=function(a){
	if (!a) return false;
	try {
		eval("var b="+a.toString());
		return typeof(b)=='object';
	}catch(e){
		return false;
	}
};

//check datatime yyyy-MM-dd hh:mm:ss
dhtmlxValidation.isValidDate=function(a){
	if (!a) return false;
	var fmt = "yyyy-MM-dd";
    var yIndex = fmt.indexOf("yyyy");
    if (yIndex ==- 1) {
        return false;
    }
    var year = v.substring(yIndex, yIndex + 4);
    var mIndex = fmt.indexOf("MM");
    if (mIndex ==- 1) {
        return false;
    }
    var month = v.substring(mIndex, mIndex + 2);
    var dIndex = fmt.indexOf("dd");
    if (dIndex ==- 1) {
        return false;
    }
    var day = v.substring(dIndex, dIndex + 2);
    if (isNaN(year) || year > "2100" || year < "1900") {
        return false;
    }
    if (isNaN(month) || month > "12" || month < "01") {
        return false;
    }
    var maxday = 31;
    if (month == 4 || month == 6 || month == 9 || month == 11) {
    	maxday = 30;
    }
    if (month == 2) {
        if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
        	maxday = 29;
        }
        else {
        	maxday = 28;
        }
    }
    if (day > maxday || day < "01") {
        return false;
    }
    return true;
};

//check datatime yyyy-MM-dd hh:mm:ss
dhtmlxValidation.isValidDatetimeSS=function(a){
	if (!a) return false;
	var regu=/^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-)) (20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d$/;
	return regu.test(a);
};

//integer >=0
dhtmlxValidation.isValidDhxWidth = function(value) {
	if ("*"==value) return true;
	return !!value.toString().match(/(^-?\d+$)/) && Number(value)>=0;
};


